package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.Map;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Api(tags="订单管理")
public class OrderController {

    @Autowired
    private OrderService OrderService;


    /**
     * 查看各个状态的订单
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("查看各个状态的订单")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO orderStatisticsVO= OrderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 订单分页查询
     * @param OrdersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单分页查询")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO OrdersPageQueryDTO){
        PageResult P=OrderService.conditionSearch(OrdersPageQueryDTO);
        return Result.success(P);
    }


    /**
     * 管理端取消订单
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO OrdersCancelDTO) throws Exception {
        OrderService.admincancelorder(OrdersCancelDTO.getCancelReason(),OrdersCancelDTO.getId());
        return Result.success();
    }

    /**
     * 拒单
     */
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO OrdersRejectionDTO ) throws Exception {
        OrderService.rejection(OrdersRejectionDTO.getRejectionReason(),OrdersRejectionDTO.getId());
        return Result.success();
    }


    /**
     * 接单
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody  Map<String,Long> Map ) {
        OrderService.confirm(Map.get("id"));
        return Result.success();
    }

    /**
     * 完成订单
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id ) {
        OrderService.complete(id);
        return Result.success();
    }

    /**
     * 查看订单详情哦
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("订单详情")
    public Result<OrderVO> details(@PathVariable Long id){
        OrderVO orderVO=OrderService.getDetails(id);
        return Result.success(orderVO);
    }
    /**
     * 派送订单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable Long id){
        OrderService.delivery(id);
        return Result.success();
    }

}
